package net.y2t72.microblog.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.y2t72.microblog.bean.District;
import net.y2t72.microblog.biz.DistrictBiz;
import net.y2t72.microblog.biz.impl.DistrictBizImpl;


public class FindCityServlet extends HttpServlet {

	/**
	 *  版本号
	 */
	private static final long serialVersionUID = 7490258147756265099L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// 字符编码
		response.setContentType("text/html;charset=utf-8");
		
		request.setCharacterEncoding("utf-8");
		
		// 向控制台输出用户想要得到的信息
		PrintWriter out = response.getWriter();
		
		// 创建省市级联业务对象
		DistrictBiz districtBiz = new DistrictBizImpl();
		
		// 通过业务对象查询省市信息
		List<District> list = districtBiz.findProvince();
		
		if(list!=null && list.size()>0){
			
			// 保存级联信息到request对象中
			request.setAttribute("district", list);
			
			// 跳回显示级联信息的页面
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}
		
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doGet(request, response);
	}

}
